package com.axon.components.containers
{
	import com.axon.base.interfaces.IAxSetInitialFocus;
	import com.axon.components.interfaces.IAxSmartContainter;
	import com.axon.mvc.events.AxViewEvent;
	import com.axon.mvc.helpers.AxVerbs;
	
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	
	import mx.containers.Panel;
	import mx.core.UIComponent;

	public class AxPanel extends Panel implements IAxSmartContainter, IAxSetInitialFocus
	{
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		private var fVo: Object = null;
		
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
   		[Inspectable(category="Other")]	public var axInitialFocusControl 	: UIComponent;
   		[Inspectable(category="Other")] public var axHandleEscapeKey 		: Boolean = true;
		
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		[Bindable]	public function get vo()					: Object		{ return fVo };
					public function set vo(valueObject: Object)	: void			{ fVo = valueObject };
					
					public function get initialFocusControl()	: UIComponent	{ return axInitialFocusControl };			
		
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		public function AxPanel()
		{
			super();
			addEventListener( KeyboardEvent.KEY_DOWN, 	onKeyDown );
		}
		
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		private function onKeyDown(event: KeyboardEvent): void
		{
			switch (event.charCode)
			{
				case Keyboard.ESCAPE: 
					if (axHandleEscapeKey) {  
						dispatchEvent( new AxViewEvent(AxVerbs.CANCEL) ); 
						dispatchEvent( new AxViewEvent(AxVerbs.CLOSE) ); } 
					break;
					
				// TODO - Não sei se deve ter aqui.
//				case Keyboard.F5:
//					dispatchEvent( new AxViewEvent(AxVerbs.REFRESH) );
			}
		}

	}
}